//
//  ZGWBiaoGeXiangJieViewController.m
//  MyYiJianKangApp
//
//  Created by 张国文 on 16/6/2.
//  Copyright © 2016年 hangzhouyijiyin. All rights reserved.
//

#import "ZGWBiaoGeXiangJieViewController.h"
#import "KWFormView.h"

@interface ZGWBiaoGeXiangJieViewController ()<KWFormViewDataSource, KWFormViewDelegate>

@property (nonatomic, strong) UIScrollView *backGroundView; // 背景

@property (nonatomic, strong) KWFormView *biaoGeXiangJieFormView; // 表格详解的上方表格

@property (nonatomic, strong) NSMutableArray *biaoGeXiangJieDataArray; // 表格详解数据源

@property (nonatomic, strong) NSMutableString *biaoGeXiangJieString; // 表格详解字符串

@end

@implementation ZGWBiaoGeXiangJieViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    // navi的修改
    [self changeNavigation];
    // 建立数据源
    [self addData];
    // 布局
    [self addMySubview];
}

// navi的修改
- (void)changeNavigation
{
    self.navigationItem.title = @"表格详解";
    UIImageView *leftImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
    leftImageView.image = [UIImage imageNamed:@"houtui"];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftImageView];
    UITapGestureRecognizer *leftTapGes = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(lastPage:)];
    [leftImageView addGestureRecognizer:leftTapGes];
    
}

#pragma mark - 返回上一页面
- (void)lastPage:(UITapGestureRecognizer *)tapGes
{
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark - 建立数据源
- (void)addData
{
    // 建立模拟数据
    self.biaoGeXiangJieDataArray = [NSMutableArray arrayWithObjects:@"1.根据六大国际权威数据库(Clinar、OMIM、HGMD、GWAS catolog、Uniprot、SNPedia)已经相关国际权威期刊和国内领域专家实验室研究综合挑选出的疾病易感基因，主要针对中国或者东亚人口。", @"2.参照美国医学遗传学与基因组学学会(ACMG)变异致病性标准，综合考虑相对风险值、人群数据、研究程度等条件严格挑选出的疾病高相关度变异位点。", @"3.一般人在基因组上一个位点的基因型有三种，如肥胖基因FTO rs3751812 基因型有三种CC、TC、TT，CC为突变基因型(肥胖风险高)，TC为杂合基因型(肥胖风险较高)，TT为正常基因型(无肥胖风险)。", @"4.某基因型在人群中出现的概率，参考1000Genome、HAPMAP、dbSNP、ExAc、SNPedia、Clinvar等变异位点信息数据库及文献得来。", @"5&6.改为点该基因型对疾病发生的影响，分为三种状态：抑制疾病发生(笑脸)、对疾病发生无影响(正常)、促进疾病发生(难过)", @"7.该疾病易感基因位点相关重要参考文献。\n注：本表格可能只成仙了部分重要的检测位点，若需了解该项目全部检测位点信息，请联系公司客服", nil];
    
    self.biaoGeXiangJieString = [NSMutableString stringWithFormat:@""];
    for (int i = 0; i < self.biaoGeXiangJieDataArray.count; i++) {
        NSString *tempString = self.biaoGeXiangJieDataArray[i];
        NSString *resultString = @"";
        if (i == (self.biaoGeXiangJieDataArray.count - 1)) {
            // 表明是最后一句话
            resultString = tempString;
        } else {
            // 表明不是最后一句话
            resultString = [NSString stringWithFormat:@"%@\n", tempString];
        }
        [self.biaoGeXiangJieString appendString:resultString];
    }
    
}

#pragma mark - 布局
- (void)addMySubview
{
    self.backGroundView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
    self.backGroundView.backgroundColor = [UIColor whiteColor];
    self.backGroundView.contentSize = CGSizeMake(kScreenWidth, 1.5 * kScreenHeight);
    self.backGroundView.bounces = NO;
    self.backGroundView.showsVerticalScrollIndicator = NO;
    [self.view addSubview:_backGroundView];
    
    self.biaoGeXiangJieFormView = [[KWFormView alloc] initWithFrame:CGRectMake(20 * kAdjustParamater, 30 * kAdjustParamater, 335 * kAdjustParamater, 71 * kAdjustParamater)];
    self.biaoGeXiangJieFormView.dataSource = self;
    self.biaoGeXiangJieFormView.delegate = self;
    [self.backGroundView addSubview:_biaoGeXiangJieFormView];
    
    // 详解内容
    UILabel *xiangJieLabel = [[UILabel alloc] initWithFrame:CGRectMake(20 * kAdjustParamater, self.biaoGeXiangJieFormView.bottom + 20 * kAdjustParamater, 340 * kAdjustParamater, 100 * kAdjustParamater)];
   // xiangJieLabel.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.1];
    xiangJieLabel.text = self.biaoGeXiangJieString;
    xiangJieLabel.textColor = [UIColor blackColor];
    xiangJieLabel.font = [UIFont systemFontOfSize:k16Big];
    xiangJieLabel.numberOfLines = 0;
    // 改变行间距
    [xiangJieLabel setAttributedText:[[NetStatusHandle shareHandle] setHangJianJvOfLabel:xiangJieLabel.text lineHeight:10]];
    [xiangJieLabel sizeToFit];
    [self.backGroundView addSubview:xiangJieLabel];
    
    // 下方灰色条
    UILabel *bottomLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, xiangJieLabel.bottom + 50 * kAdjustParamater, kScreenWidth, 10 * kAdjustParamater)];
    bottomLabel.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.05];
    [self.backGroundView addSubview:bottomLabel];
    
    // 改变背景大小
    
    self.backGroundView.contentSize = CGSizeMake(kScreenWidth, bottomLabel.bottom + 30 * kAdjustParamater);
}

#pragma mark - 表格代理
- (NSInteger)numberOfRowsInFormView:(KWFormView *)formView
{
    return 2;
}

- (NSInteger)formViewColumnsInRow:(KWFormView *)formView
{
    return 7;
}

- (CGFloat)formView:(KWFormView *)formView widthForColumn:(NSInteger)column
{
    return 335 / 7 * kAdjustParamater;
}

- (CGFloat)formView:(KWFormView *)formView heightForRow:(NSInteger)row
{
    if (row == 0) {
        return 17 * kAdjustParamater;
    }
    return 54 * kAdjustParamater;
}

- (NSString *)formView:(KWFormView *)formView textForColumn:(NSInteger)column inRow:(NSInteger)row
{
    if (row == 0) {
        if (column == 0) {
            return @"1";
        } else if (column == 1) {
            return @"2";
        } else if (column == 2) {
            return @"3";
        } else if (column == 3) {
            return @"4";
        } else if (column == 4) {
            return @"5";
        } else if (column == 5) {
            return @"6";
        } else if (column == 6) {
            return @"7";
        }
    } else if (row == 1) {
        if (column == 0) {
            return @"基因";
        } else if (column == 1) {
            return @"检测\n位点";
        } else if (column == 2) {
            return @"基因型";
        } else if (column == 3) {
            return @"基因型\n概率";
        } else if (column == 4) {
            return @"评价";
        } else if (column == 5) {
            return @"影响";
        } else if (column == 6) {
            return @"参考\n文献";
        }
    }
    return nil;
}

- (UIColor *)formView:(KWFormView *)formView colorOfColumn:(NSInteger)column inRow:(NSInteger)row
{
    return [UIColor whiteColor];
}

- (UIColor *)formView:(KWFormView *)formView contentColorOfColumn:(NSInteger)column inRow:(NSInteger)row
{
    return [UIColor blackColor];
}

- (UIColor *)formViewBorderColor:(KWFormView *)formView
{
    return kCyanColor;
}

- (UIFont *)formViewFontOfContent:(KWFormView *)formView
{
    return [UIFont systemFontOfSize:k13Big];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
